<!DOCTYPE html>
<html lang="en">
<head>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <title>返修</title>
    <link rel="stylesheet" type="text/css" href="__CSS__/reset.css">
    <link rel="stylesheet" type="text/css" href="__CSS__/wechat/adds.css">
    <script src="__JS__/libs/jquery-2.0.2.min.js"></script>
    <script type="text/javascript" src="__JS__/swayPlugIn.js"></script>
    <script src="__JS__/dialog/layer.js"></script>
    <script src="__JS__/vue.js"></script>
    <style>
    	@media screen and (max-width: 300px) {
    		
    	}
    </style>
</head>
<body>
    <div id="contentBox">
        <div class="row row1">
            <div>
                <form id="form1" method="post" action="" enctype="multipart/form-data">
                	<div class="one" style="margin-top:5px;">
                        <label for="username">审查人：</label>
                        <input type="text" disabled="disabled" value="" name=""/>
                    </div>
                    <div class="one" style="margin-top:5px;">
                        <label for="username">审查人职务：</label>
                        <input type="text" disabled="disabled" value="" name=""/>
                    </div>
                    <div class="one" style="margin-top:5px;">
                        <label for="username">重修备注：</label>
                        <span>bbbbb</span>
                    </div>
                    <div class="one">
                        <label for="username">提交人：</label>
                        <input type="text" disabled="disabled" value="" name=""/>
                    </div>
                     <div class="one" style="position: relative;">
                        <label for="username">负责人：</label>
                        <input type="text"  name="" list="peple"  v-model="fzr" @keyup="fzrck"/>
						<ul v-if="lists7.length!=0" style="position:absolute;width: 75%;display: block;background: white; left: 25%; top:50px;z-index: 4000;border:1px solid #ccc;">
							<li @click="fzrck3(list7.name,list7.rname,list7.uid)" style="height: 30px;line-height: 30px;border-bottom:1px solid #ccc;" v-for="list7 in lists7">{{list7.name}}&nbsp;&nbsp;&nbsp;{{list7.rname}}</li>
						</ul>
						  	<!--<option :value="list7.name+'  '+list7.rname" v-if="fzr!=''" v-for="list7 in lists7"><span></span></option>					  	
						</datalist>-->
						<input type="hidden" name="uid" v-model="list7uid"/>
                    </div>
                    <div class="one">
                        <label for="username">收货地址：</label>
                        <span class="adspan" @click="choose_ad">
                        	<div style="float: left;width: 33.2%;">{{name_tel}}</div>
                        	<div style="float: right;width: 60.2%;">
                        		{{adress}}
                        	</div></span>
                        	<i></i>
                        <input type="hidden" v-model="aid" name="aid"/>
                        
                    </div>
                   
                    <div class="three">
                        <div style="width: 100%;height: 32px;clear: both; font-size: 14px; line-height: 32px;text-indent: 10px;">产品：</div>
                        <div style="margin-left:2.5%;width: 95%;height: 270px;border:1px solid #ddd;border-radius: 5px;">                       	
                        	<table class="table2">
                        		<thead>
	                        		<tr>
	                        			<th>名称</th>
	                        			<th>规格</th>
	                        			<th>类型</th>
	                        			<th>单价</th>
	                        			<th>操作</th>
	                        		</tr>	
                        		</thead>  
                        	</table>
                        		
                        	<table class="table">	
                        		<tbody>
                        			<tr v-for="(list,index) in lists2">
	                        			<td>	
	                        				{{list.name}}
	                        			</td>
	                        			<td>
	                        				{{list.standard}}
	                        			</td>
	                        			<td>{{list.type}}</td>
	                        			<td>
	                        				{{list.price}}
	                        			</td><!-- v-model="goods_num[index]"-->
	                        			<td style="padding:5px 0 0 0px;min-width: 70px;">
	                        				<div v-if="list.time>0" class="addlogo" @click="list.time--">-</div>
	                        				<input v-if="list.time>0" type="number" class="list_num" name="" :value="list.time" style="width: 28px;float: left;"/>
	                        				<div :class="{'addlogo':list.time>0,'addlogo2':list.time==0}" @click="addtime(index)">+</div>
	                        			</td>
	                        		</tr>			                        		
                        		</tbody>
                        		<input type="hidden" name="goods_id" v-model="goods_id1" id="goods_id"/>
                        		<input type="hidden" name="goods_num" v-model="goods_num1"/>
                        	</table>
                        </div>
                    </div>
                     <div class="one">
                        <label for="username">备注：</label>                       
                       <textarea name="notes" rows="" cols="" v-model="notes" style="flex:1;margin:5px 0;"></textarea>
                    </div>
                    <div class="three">
                    	<table class="table2" style="width: 100%;">	
                    		<thead>
                    			<tr>
                    				<th>名称</th>
                    				<th>规格</th>
                    				<th>类型</th>
                    				<th>价格</th>
                    				<th>数目</th>
                    			</tr>
                    		</thead>
                    		<tbody>
                    			<tr v-for="(list,index) in lists2" v-if="list.time!==0">
                        			<td>	
                        				{{list.name}}
                        			</td>
                        			<td>
                        				{{list.standard}}
                        			</td>
                        			<td>{{list.type}}</td>
                        			<td>
                        				{{list.price}}
                        			</td><!-- v-model="goods_num[index]"-->
                        			<td style="padding:3px 0 0 15px;">
                        				<div class="addlogo" @click="list.time--">-</div>
                        				<input type="number" name="" :value="list.time" style="width: 28px;float: left;"/>
                        				<div class="addlogo" @click="addtime(index)">+</div>
                        			</td>
                        		</tr>			                        		
                    		</tbody>                    		
                    	</table>
                    </div>
                     <div class="one" style="padding-left: 50%;">
                        <div style="float: right;">总价：</div>
                        <span style="font-size: 16px;color: darkred;">￥{{prices}}</span>
                    </div>
                    <div class="two">
                        <button type="button" id="send" @click="send">提交</button>
                    </div>
                    <div class="adress_page" style="position: fixed;z-index: 200;" :class="{'adress_page2':isaa,'adress_page3':isbb}">
                    	<div class="adress_tit">
                    		<div class="history_bk" @click="history_go"></div>
                    		<div class="adress_show">{{adress}}</div>
                    	</div>
                    	<div class="adress_body">
	                    	<ul v-if="ismemo">
		                    	<li v-for="(list,index) in lists1" @click="choosepid(list.name,list.id)">{{list.name}}</li>
	                    	</ul>
	                    	<ul v-else="ismemo" class="memoinfo">
	                    		<li><input type="text" placeholder="请输入联系人详细地址" v-model="per.memo"/></li>
	                    		<li><input type="text" placeholder="请输入联系人姓名"  v-model="per.name"/></li>
	                    		<li><input type="text" placeholder="请输入联系人电话" v-model="per.tel"/></li>
	                    		<div class="add_adress" @click="sure_memo(per.memo,per.name,per.tel)">
	                    			确认
	                    		</div>
	                    	</ul>
                    	</div>                   	                   	
                    </div>
                    <div class="adress_page" style="position: fixed;z-index: 100;" :class="{'adress_page2':isa,'adress_page3':isb}">
                    	<div class="adress_tit">
                    		<div class="adress_show">选择地址</div>
                    	</div>
                    	<div class="adress_body"> 
	                    	<ul>
	                    		<li v-for="(list3,index) in lists3" class="list3_memo" :class="{'list3_memo2':list3.status==1}" @click="choose_adre(index,list3.pname,list3.cname,list3.aname,list3.memo,list3.id,list3.receiver,list3.tel)">
	                    			<div style="width:38.2%;height: 50px;float: left;line-height: 25px;"><div>{{list3.receiver}}</div><div>{{list3.tel}}</div></div>
	                    			<div style="width: 61.8%;height: 50px;float: left;line-height: 25px;" >{{list3.pname}} {{list3.cname}} {{list3.aname}} {{list3.memo}}</div>
	                    		</li>
	                    	</ul>
	                    	<div class="add_adress" @click="addadress">新增地址</div>
                    	</div>                   	                   	
                    </div>
                </form>                
            </div>
        </div>       
    </div>
    
</body>
<script type="text/javascript">			
	
    var vm=new Vue({
    	el:"#form1",
    	data:{
    		isa:false,
    		isb:false,
    		isaa:false,
    		isbb:false,
    		adress:"选择地址",
    		adUrl:"/manage/user/areas",
    		lists1:[],
    		num:0,
    		num2:0,
    		aid:"",
    		adinfo:false,
    		lists2:[],
    		goods_id:[],
    		goods_id1:"",
    		goods_num:[],
    		goods_num2:[],
    		goods_num1:"",
    		lists3:[],
    		lists4:[
    		],
    		pname:"",
    		cname:"",
    		aname:"",
    		admemo:"",
    		ismemo:true,
    		per:{memo:"",name:"",tel:""},
    		name_tel:"",
    		fzr:"",
    		lists7:[
    		],
    		list7uid:"",
    		notes:""
    	},
    	 computed:{
    	 	prices:function(iterm,index){
      	 			var len=this.lists2.length;
    	 			var pricess=0;
					for(var i=0;i<len;i++){
						pricess=pricess+this.lists2[i].price*this.lists2[i].time;
					}   
					return pricess.toFixed(2);
    	 	},
    	 },
    	methods:{
    		choose_ad:function(){
    			this.isb=false;
    			this.isa=true;
    			var _this = this;
	    		$.post(this.adUrl,{pid:1},function(data){
	    			var data=JSON.parse(data);
	    			var data=data.data;    			
	    			_this.lists1=data;
	    		})
    		},
    		addtime:function(index){
    			this.lists2[index].time++;
    		},
    		fzrck3:function(name,rname,uid){
    			this.fzr=name+'  '+rname;
    			this.lists7.length=0;
    			this.list7uid=uid;
    		},
    		fzrck:function(){
    			var _this=this;
    			$.post("{{:url('wechat/Cons/getresponseinfo')}}",{name:this.fzr},function(data){
	    			var data=JSON.parse(data);
		    		var data=data.data; 		    		
		    		_this.lists7=data;
		    		console.log(data)
	    		})
    		},
    		history_go:function(){
    			this.num=0;
    			var _this=this;
    			if(this.isaa){
    				this.isbb=true;
    				this.isaa=false;
    			}
    			$.post(this.adUrl,{pid:1},function(data){
	    			var data=JSON.parse(data);
	    			var data=data.data;    			
	    			_this.lists1=data;
	    			_this.adress="";
	    			_this.ismemo=true;
	    		})
    		},
    		choose_adre2:function(adress,memo,id){
    			var _this=this;
    			$.ajax({
					type:"post",
					url:"{{:url('wechat/Cons/saveAddressStatus')}}",
					data:{						
						id:id						
					},success:function(data){
						_this.adress=adress+" "+memo;
		    			_this.admemo=memo;
		    			if(_this.isa){
		    				_this.isb=true;
		    				_this.isa=false;
		    			}
		    			_this.adinfo=true;
		    			_this.aid=id;		
					}
				});
    		},
    		choose_adre:function(index,pname,cname,aname,memo,id,receiver,tel){ 
    			for(var i=0;i<this.lists3.length;i++){
    				this.lists3[i].status=0;
    				this.lists3[index].status=1;
    			}
    			
    			var _this=this;
    			$.ajax({
					type:"post",
					url:"{{:url('wechat/Cons/saveAddressStatus')}}",
					data:{						
						id:id						
					},success:function(data){
						_this.adress=pname+" "+cname+" "+aname+" "+" "+memo;
		    			_this.admemo=memo;
		    			_this.name_tel=receiver+" "+tel;
		    			if(_this.isa){
		    				_this.isb=true;
		    				_this.isa=false;
		    			}
		    			_this.adinfo=true;
		    			_this.aid=id;		
					}
				});
    		},
			addadress:function(){
				this.isaa=true;
				this.isbb=false;
			},
			sure_memo:function(memo,name,tel){
				console.log(this.per.memo,this.per.name,this.per.tel)
				var per_memo=this.per.memo.length;
				var per_name=this.per.name.length;
				var per_tel=this.per.tel;
				if(per_memo==0){
					layer.msg("请输入详细地址~");
					return;
				}
				if(per_name==0){
					layer.msg("请输入收货人姓名~");
					return 
				}
				if(!(/^1[34578]\d{9}$/.test(per_tel))){
					layer.msg("请输入正确电话号码~");
					return 
				}
				var _this=this;
				var obj={};
				$.ajax({
					type:"post",
					url:"{{:url('wechat/Cons/insertaddress')}}",
					data:{
						receiver:name,
						tel :tel,
						memo :memo,
						pid :_this.pid,
						cid:_this.cid,
						aid:_this.aid						
					},success:function(data){
						var data=JSON.parse(data);
						console.log(data)					
						if(data.status==1){
							var data=data.data;
							_this.isbb=true;
	  						_this.isaa=false;
		    				_this.ismemo=true;
		    				var obj={pname:_this.pname,cname:_this.cname,aname:_this.aname,memo:memo,id:_this.id,receiver:name,tel:tel,status:0,id:data};
		    				console.log(1,obj.uid)
		    				_this.lists3.unshift(obj);
						}else{
							alert(data.message)
						}
						
					}
				});
			},			
    		send:function(){ 
    			this.goods_num2=[];
    			this.goods_id=[];
    			var len=this.lists2.length;
    			var len2=this.fzr.length;
    			var that=this;
    			if(len==0){
    				layer.msg("请添加商品~");
    				return
    			}    			   			
    			
    			for(var i=0;i<len;i++){
    				if(this.lists2[i].time!=0){
    					this.goods_num2.push(this.lists2[i].time);
    					var j=i+1;
    					this.goods_id.push(j);
    				}    				
    			}
	    		this.goods_id1=this.goods_id.join(",");
	    		this.goods_num1=this.goods_num2.join(",");
    			$.ajax({
    				type:"post",
    				url:"{{:url('wechat/Cons/aorder')}}",
    				data:{
    					uid:that.list7uid,
    					aid:that.aid,
    					goods_id:that.goods_id1,
    					goods_num:that.goods_num1,
    					notes:that.notes
    				},
    				success:function(data){
    					console.log(that.goods_id1,that.goods_num1)
    					var data=JSON.parse(data);
    					if(data.status==1){
//  						console.log(data)
    						var data=data.data;
    						layer.msg("提交成功！");
    						setTimeout(function(){
    							window.location.href=data.url;
    						},1500);
    						
    					}else{
    						layer.msg(data.message)
    					}   					
    				}
    			});
    		
    		
//	    		setTimeout(function(){
//	    			$("#form1").submit();
//	    		},100);		 	
    		},
    		choosepid:function(name,id){
    			var _this = this;
	    		$.post(this.adUrl,{pid:id},function(data){
	    			var data=JSON.parse(data);
	    			var data=data.data;    			
	    			_this.lists1=data;
	  				_this.num++;
	  				if(_this.num==1){
	  				_this.adress=name;
	  				_this.pname=name;
	  				_this.pid=id;
	  				_this.cname="";
	  				_this.aname="";
	  				}else if(_this.num==2){
	  					_this.adress=_this.adress+" "+name;
	  					_this.cname=name;
	  					if(data.cname==""){
	  						_this.cname="";
	  					}
	  					_this.cid=id;
	  				}else if(_this.num==3){
	  					_this.aname=name;
	  					_this.aid=id;
	  					_this.adress=_this.adress+" "+name;
	  					if(data.aname==""){
	  						_this.aname="";
	  					}
	  				}
	    			if(data.length===0){
						_this.ismemo=false;
	    			}	    			
	    		})
    		}
    	},created:function(){
    		var _this=this;
    		$.post("{{:url('wechat/Cons/prolist')}}",{},function(data){
    			var data=JSON.parse(data);   			
	    		var data=data.data; 	    		
	    		_this.lists2=data;
	    		for(var i=0;i<data.length;i++){
	    			data[i].time=0;
	    		}
	    		for(var i=0;i<data.length;i++){
	    			_this.goods_num.push(0);
	    		}
	    		if($(".list_num").val()<0){
	    			$(".list_num").val(0);
	    		}
    		})
    		$.post("{{:url('wechat/Cons/addresslist')}}",{},function(data){
    			var data=JSON.parse(data);
	    		var data=data.data; 
	    		_this.lists3=data;
	    		for(var i=0;i<data.length;i++){
	    			if(data[i].status==1){
	    				_this.name_tel=data[i].receiver+data[i].tel;
	    				_this.adress=data[i].pname+" "+data[i].cname+" "+data[i].aname+" "+data[i].memo;
	    				_this.aid=data[i].id;	    				
	    			}
	    		}	    		
    		})    		    		
    	}
    })
</script>
</html>
